/**
 *@title
 *@author huahuadavids
 *@date 2020/4/11
 */
import * as types from "../types"
const state1 = {
  item: [] ,
  complete: false
}

export default function (state=state1, action) {
  switch (action.type) {
    case types.ADD_TODO:
      return{
        item: [...state.item, {text: action.text, complete: false}]
      }
    case types.DEL_TODO:
      return {
        item: [...state.item.slice(0, action.index), ...state.item.slice(action.index+1)]
      }
    case types.TOGGLE_TODO:
      return {
        item: state.item.map((item,index) => {
          if(index === action.index){
            item.complete = !item.complete
          }
          return item;
        })
      }
    default:
      return state;
  }
}
